package com.traffic.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.traffic.domain.PerBusinessTripApplication;
import com.traffic.service.IPerBusinessTripApplicationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 出差申请Controller
 * 
 * @author 郭世纪
 * @date 2024-12-08
 */
@RestController
@RequestMapping("/business")
public class PerBusinessTripApplicationController extends BaseController
{
    @Autowired
    private IPerBusinessTripApplicationService perBusinessTripApplicationService;

    /**
     * 查询出差申请列表
     */
    @RequiresPermissions("attendance:business:list")
    @GetMapping("/list")
    public TableDataInfo list(PerBusinessTripApplication perBusinessTripApplication)
    {
        startPage();
        List<PerBusinessTripApplication> list = perBusinessTripApplicationService.selectPerBusinessTripApplicationList(perBusinessTripApplication);
        return getDataTable(list);
    }

    /**
     * 导出出差申请列表
     */
    @RequiresPermissions("attendance:business:export")
    @Log(title = "出差申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PerBusinessTripApplication perBusinessTripApplication)
    {
        List<PerBusinessTripApplication> list = perBusinessTripApplicationService.selectPerBusinessTripApplicationList(perBusinessTripApplication);
        ExcelUtil<PerBusinessTripApplication> util = new ExcelUtil<PerBusinessTripApplication>(PerBusinessTripApplication.class);
        util.exportExcel(response, list, "出差申请数据");
    }

    /**
     * 获取出差申请详细信息
     */
    @RequiresPermissions("attendance:business:query")
    @GetMapping(value = "/{tripId}")
    public AjaxResult getInfo(@PathVariable("tripId") Long tripId)
    {
        return success(perBusinessTripApplicationService.selectPerBusinessTripApplicationByTripId(tripId));
    }

    /**
     * 新增出差申请
     */
    @RequiresPermissions("attendance:business:add")
    @Log(title = "出差申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PerBusinessTripApplication perBusinessTripApplication)
    {
        return toAjax(perBusinessTripApplicationService.insertPerBusinessTripApplication(perBusinessTripApplication));
    }

    /**
     * 修改出差申请
     */
    @RequiresPermissions("attendance:business:edit")
    @Log(title = "出差申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PerBusinessTripApplication perBusinessTripApplication)
    {
        return toAjax(perBusinessTripApplicationService.updatePerBusinessTripApplication(perBusinessTripApplication));
    }

    /**
     * 删除出差申请
     */
    @RequiresPermissions("attendance:business:remove")
    @Log(title = "出差申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tripIds}")
    public AjaxResult remove(@PathVariable Long[] tripIds)
    {
        return toAjax(perBusinessTripApplicationService.deletePerBusinessTripApplicationByTripIds(tripIds));
    }
}
